const spawn = require("child_process").spawn
const py = spawn("python", [__dirname + '\\cluster\\cluster.py'])

cluster = {
    search_tag: "小米",
    detail: ["11", "pro", "发布会"]
}

chunks = []

// 获取python返回的值
py.stdout.on("data", data => chunks.push(data))

// 当python子进程结束时，输出返回的东西
py.stdout.on('end', function () {
    try {
        const data = JSON.parse(Buffer.concat(chunks).toString());
        console.log(data)
        console.log("python process END...")
    }
    catch (e) {
        console.log(e)
    }
});

// 将json传给python
jsonData = JSON.stringify(cluster)

py.stdin.write(jsonData)
py.stdin.end()